﻿Ext.define('MyApp.models.Invoice', {
    extend: 'Ext.data.Model',

    hasMany: [{
        model : 'MyApp.models.Item',
        name : 'getItems'
    }],

    idProperty: 'idInvoice',
    fields: [
        { name: 'IdInvoice' },
        { name: 'taxId' },
        { name: 'dateIssued', type: 'date', dateFormat: 'Y-m-d h:i:s' },
        { name: 'name' },
        { name: 'address' }
    ],

    validations: [
        { type: 'presence', field: 'taxId' },
        { type: 'length', field: 'taxId', min: 5, max: 7 },
        { type: 'presence', field: 'name' },
        { type: 'format', field: 'name', matcher: /^[\w ]+$/ }
    ]
});